package com.gilight.base.base;

/**
 * Created by zhaowuz on 2018/8/21.
 */
public enum RepStatusCode {

    UNKNOWN_ERROR(-1, "system is busy", "系统繁忙"),
    SUCCESS(1000, "success", "请求成功"),
    BUSINESS_ERROR(5001, "business_error", "业务异常"),
    ILLEGAL_PARAMETER_ERROR(5002, "illegal_argument_error", "参数错误"),
    NO_AUTH_ERROR(403, "no_auth_error", "权限认证错误");

    private int code;
    private String reason;
    private String description;

    RepStatusCode(int code, String reason, String description) {
        this.code = code;
        this.reason = reason;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public RepStatusCode setCode(int code) {
        this.code = code;
        return this;
    }

    public String getReason() {
        return reason;
    }

    public RepStatusCode setReason(String reason) {
        this.reason = reason;
        return this;
    }

    public String getDescription() {
        return description;
    }

    public RepStatusCode setDescription(String description) {
        this.description = description;
        return this;
    }

    public static String toMarkdownTable() {
        StringBuilder stringBuilder = new StringBuilder("error_code | error_reason | error_description");
        stringBuilder.append("\n:-: | :-: | :-:\n");
        for (RepStatusCode error : RepStatusCode.values()) {
            stringBuilder.append(String.format("%s | %s | %s", error.getCode(), error.getReason(), error.getDescription())).append("\n");
        }
        return stringBuilder.toString();
    }

}
